<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加患者</title>
</head>
<link rel="stylesheet" href="/static/layui/css/layui.css"/>
<body>
<form class="layui-form" id="user-add" action="" lay-filter="add">
    <input type="hidden" name="pid">
    <div class="layui-form-item">
        <label class="layui-form-label">医院名称</label>
        <div class="layui-input-inline layui-col-md4">
            <select name="hospital.hid" id="hid" lay-filter="aihao">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">治疗医生</label>
        <div class="layui-input-inline layui-col-md4">
            <select name="doctor.did" id="did" lay-filter="aihao">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文件</label>
        <div class="layui-input-inline layui-col-md4">
            <select name="files.uposition"  lay-filter="aihao">
                  <option value="0">遗传诊断报告</option>
                <option value="1">基因检测报告</option>
                <option value="2">诊断病例</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">项目名称:</label>
        <div class="layui-input-inline layui-col-md4">
            <input type="text" name="files.cname" lay-verify="required|aname" lay-reqtext="项目名称是必填项，岂能为空？" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-inline layui-col-md4">
            <input type="tel" name="pusername" lay-verify="required|phone" placeholder="请输入手机号正确格式11位" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline layui-col-md4">
            <input type="password" name="ppassword" placeholder="请输入密码" required lay-verify="required|pass" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请务必填写账号</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名:</label>
        <div class="layui-input-inline layui-col-md4">
            <input type="text" name="pname" lay-verify="required|aname" lay-reqtext="姓名是必填项，岂能为空？" placeholder="请输入真实姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="psex" value="男" title="男" checked="">
            <input type="radio" name="psex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline layui-col-md4">
                <input type="tel" name="pphone" lay-verify="required|phone" placeholder="请输入手机号正确格式11位" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址：</label>
        <div class="layui-input-inline layui-col-md4">
            <input type="text" name="paddress" lay-verify="required" autocomplete="off" placeholder="请输入地址" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline layui-col-md4">
                <input type="text" name="pemail" lay-verify="email" placeholder="请输入正确邮箱格式" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否发送:</label>
        <div class="layui-input-block">
            <input type="radio" name="send" value="0" title="是">
            <input type="radio" name="send" value="1" title="否" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>

<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
    //医院下拉款
    layui.use(['form','laydate'], function() {
        var form = layui.form;
        $.ajax({
            url: "/hospital/findAll",
            type: "post",
            // data:{},
            dataType: "json",
            success: function (res) {
                console.log(res)
                $.each(res.date.list, function (i, obj) {
                    console.log(obj);
                    $("#hid").append('<option value="' + obj.hid + '">' + obj.hname + '</option>');
                });
                form.render('select'); //刷新select选择框渲染
            }
        });
        //医生
        $.ajax({
            url: "/doctor/showhospital",
            type: "post",
            // data:{},
            dataType: "json",
            success: function (res) {
                console.log(res)
                $.each(res.date.list, function (i, obj) {
                    console.log(obj);
                    $("#did").append('<option value="' + obj.did + '">' + obj.dname + '</option>');
                });
                form.render('select'); //刷新select选择框渲染
            }
        });
        //角色
        $.ajax({
            url: "/RoleController/selectAll1",
            type: "post",
            // data:{},
            dataType: "json",
            success: function (res) {
                console.log(res)
                $.each(res.date.list, function (i, obj) {
                    console.log(obj);
                    $("#rid").append('<option value="' + obj.rid + '">' + obj.roleType + '</option>');
                });
                form.render('select'); //刷新select选择框渲染
            }
        });
    });
    layui.use(['form','jquery','layer'], function () {
        var layer = layui.layer
            , form = layui.form
            , $ = layui.$;
        //校验
        form.verify({
            //用户名必须为中文
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[\u4e00-\u9fa5\]+$").test(value)) {
                    return '姓名只能是中文';
                }
            },pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });
        //校验
        form.verify({
            //用户名必须为中文
            aname: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[\u4e00-\u9fa5\]+$").test(value)){
                    return '姓名只能是中文';
                }

            },
            ausername: function(value, item){ //value：表单的值、item：表单的DOM对象
                var message = '';
                $.ajax({
                    type:"POST",
                    url:'/checkUser',//(对应后台的方法),
                    async: false, //改为同步请求
                    datas:{ausername:value},
                    dataType:'json',
                    success:function(data){
                        alert(data);
                        if(data.code == 200){

                        }else{
                            message ="账号已存在，请重新输入！"
                        }
                    }
                });
                //需要注意 需要将返回信息写在ajax方法外
                if (message !== '')
                    return message;
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '账号不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '账号首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '账号不能全为数字';
                }
            }
            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });
    });
    //Demo
    layui.use(['form', 'laydate'], function () {
        var form = layui.form
            , laydate = layui.laydate;
        laydate.render({
            elem: '#ptime'
        });
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var data1 = form.val("add");
            $.ajax({
                url: '/patient/insert',
                type: "post",
                dataType: "json",
                data: data1,
                success: function (da) {
                    if (da.code == 200) {
                        layer.alert("添加成功！", function () {
                            // window.parent.location.reload();//刷新父页面
                            // parent.layer.close(layer.index);//关闭弹出层
                            parent.layer.closeAll();
                        });
                    } else {
                        layer.msg("添加失败！");
                    }
                }
            });
            return false;
        });
    });
</script>
</html>